package com.cuotigou.controller;

import com.cuotigou.mapper.SSuggestMapper;
import com.cuotigou.mapper.SUserMapper;
import com.cuotigou.pojo.SSuggest;
import com.cuotigou.pojo.SUser;
import com.cuotigou.util.CommonUtils;
import com.cuotigou.util.ObjectResult;
import com.cuotigou.util.StringUtil;
import com.cuotigou.util.XMLBean;
import org.apache.solr.client.solrj.response.SpellCheckResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import sun.dc.pr.PRError;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2018/12/27.
 */
@Controller
@RequestMapping("/suggest")
public class SuggestCotroller {

    @Autowired
    private SSuggestMapper sSuggestMapper;
    @Autowired
    private SUserMapper sUserMapper;

    /**
     * 意见反馈
     * @param xmlBean
     * @return
     */
    @RequestMapping(value = "/feedback", method = RequestMethod.POST, produces = "application/json")
    @ResponseBody
    public ObjectResult feedback(XMLBean xmlBean){
        try {
            if(StringUtil.isEmpty(xmlBean.getToken()) || StringUtil.isEmpty(xmlBean.getContent())){
                return ObjectResult.build("0","参数丢失请重试");
            }

            String userId = CommonUtils.decToken(xmlBean.getToken());
            SUser sUser = sUserMapper.selectByPrimaryKey(Long.parseLong(userId));


            SSuggest sSuggest = new SSuggest();
            sSuggest.setUserId(Long.parseLong(userId));
            sSuggest.setContactWay(sUser.getMobile());
            sSuggest.setContent(xmlBean.getContent());
            sSuggest.setAddTime(new Date());
            sSuggest.setModifyTime(new Date());
            sSuggestMapper.insertSelective(sSuggest);
        }
        catch (Exception e){
            e.printStackTrace();
            return ObjectResult.build("0","反馈失败");
        }
        return ObjectResult.build("1","反馈成功");
    }
}
